<template>
  <div>
    <h1>人员列表</h1>
    <input type="text" placeholder="请输入名称" v-model="name">
    <button @click="add">添加</button>
    <ul>
        <li v-for="p in personList" :key="p.id">{{p.name}}</li>
    </ul>
    <h2>Count组件的求和为{{sum}}</h2>
  </div>
</template>

<script>
import {nanoid} from 'nanoid'
export default {
  name:'person',
  data() {
    return {
        name:''
    }
  },
  computed:{
    personList(){
        return  this.$store.state.personList
    },
    sum(){
        return this.$store.state.num
    }
  },
  methods:{
    add(){
        const person = {id:nanoid(),name:this.name}
        console.log(person)
        this.$store.commit('ADD_PERSON',person)
        this.name=''
        // this.$store.dispatch('add',)
    }
  }
}
</script>

<style>

</style>